#include <iostream>
#include "opt_vertor.h"

//
// Created by Javery Chiang on 2024/6/30.
//


using namespace std;

void opt_default_vector() {// 同一指针,复制构造
    vector<shared_ptr<Item>> vector1{ make_shared<Item>(50)};

    vector<shared_ptr<Item>> vector2;
    vector2.push_back(make_shared<Item>(1));

    for (auto item = begin(vector1); item != end(vector1); ++item) {
        cout << &item << endl;
    }

    vector<Item> vector3{Item{10}};
    vector<Item> vector4{Item{20}};
    vector3 < vector4 ? cout << "vector2 " << endl : cout << "vector1 " << endl;
}


void opt_vector_prt() {
    // 存放指针需要手动释放或使用智能指针
    vector<Item *> *item_prt = new vector<Item *>(19, new Item{20});
    print_vector(*item_prt);
    // 无效只释放vector，vector中元素未释放，内存泄漏
    delete item_prt;
    item_prt = nullptr;
}

// 变量元素逐个比较
void opt_vector_compare(){
    vector <int> v1, v2;
    v1.push_back( 1 );
    v1.push_back( 2 );
    v1.push_back( 4 );

    v2.push_back( 1 );
    v2.push_back( 4 );

    if ( v1 < v2 )
        cout << "Vector v1 is less than vector v2." << endl;
    else
        cout << "Vector v1 is not less than vector v2." << endl;
}
int main() {
    opt_default_vector();

}

